#include <stdio.h>
#include <stdlib.h>
#include "TypeDef.h"
#include "Table.h"

/*
static int Compareint32_t(void *ll,void *rr)
{
	Type_t l = *(Type_t*)ll;
	Type_t r = *(Type_t*)rr;
	int32_t a = *(int32_t*)l->data;
	int32_t b = *(int32_t*)r->data;
	if(a == b)
		return 0;
	else if(a < b)
		return -1;
	return 1;
}
*/
/*
int cmp(void *ll,void *rr)
{
	int l = *(int*)ll;
	int r = *(int*)rr;
	if(l == r)
		return 0;
	else if(l < r)
		return -1;
	return 1;
}
*/

int main()
{
/*
	map_t m = map_create(sizeof(int),sizeof(int),Compareint32_t,0);
	int i = 0;
	
	for(i = 0; i < 10; ++i)
	{
		Type_t t = CreateType(&i,T_INTEGER32);
		//printf("%d\n",t);
		MAP_INSERT(Type_t,Type_t,m,t,t);
	}
	printf("-------------------\n");
	map_iter it = map_begin(m);
	map_iter end = map_end(m);
	for( ; !map_iter_equal(it,end); it = IT_MAP_NEXT(it))
	{
		int tmp;
		Type_t t = IT_MAP_GETFIRST(Type_t,it);
		t->Get(t,&tmp);
		printf("%d\n",tmp);
	}
	int k = 8;
	Type_t key = CreateType(&k,T_INTEGER32);
	printf("%d\n",key);
	map_iter it = MAP_FIND(Type_t,m,key);
	if(!map_iter_equal(it,map_end(m)))
		printf("find\n");	
*/
	Index_t idt = CreateIndex(0);
	int i;
	for(i = 0; i < 10; ++i)
	{
		Row_t r = malloc(sizeof(*r));
		r->filds = vector_create(sizeof(Type_t),0);
		int j;
		for(j = i; j < i+10; ++j)
		{
			Type_t t = CreateType(&j,T_INTEGER32);
			VECTOR_PUSH_BACK(Type_t,r->filds,t);
		}
		Type_t key = VECTOR_GET(Type_t,r->filds,0);
		Index_AddRow(idt,r,0,0);
	}
	
	printf("-------------------\n");
	/*map_iter it = map_begin(idt->rows);
	map_iter end = map_end(idt->rows);
	for( ; !map_iter_equal(it,end); it = IT_MAP_NEXT(it))
	{
		int tmp;
		Type_t t = IT_MAP_GETFIRST(Type_t,it);
		t->Get(t,&tmp);
		printf("%d\n",tmp);
	}
*/	
	

	int k = 8;
	Type_t key = CreateType(&k,T_INTEGER32);
	map_iter it = MAP_FIND(Type_t,idt->rows,key);
	if(!map_iter_equal(it,map_end(idt->rows)))
		printf("find\n");
	return 0;
}